/*
 * @Author: your name
 * @Date: 2020-08-26 15:39:41
 * @LastEditTime: 2020-08-26 15:50:57
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /decorator/src/reflect.ts
 */
	
import 'reflect-metadata';

class User {
  @Reflect.metadata('data', 'test')
  @Reflect.metadata('data1', 'test')
  getName() {}
}

class Teacher extends User {}

console.log(Reflect.getOwnMetadataKeys(User.prototype, 'getName'));
console.log(Reflect.getOwnMetadataKeys(Teacher.prototype, 'getName'));


// 装饰器的执行顺序
function showData(target: typeof User1) {
  for (let key in target.prototype) {
    const data = Reflect.getMetadata('data', target.prototype, key);
    console.log(data);
  }
}

function setData(dataKey: string, msg: string) {
  return function(target: User1, key: string) {
    Reflect.defineMetadata(dataKey, msg, target, key);
  };
}

@showData
class User1 {
  @setData('data', 'age')
  getName() {}

  @setData('data', 'age')
  getAge() {}
}
